﻿using Aweber;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Aweber.Entity;
using System.Configuration;

namespace IntegrationTests
{


    /// <summary>
    ///This is a test class for APITest and is intended
    ///to contain all APITest Unit Tests
    ///</summary>
    [TestClass()]
    public class APITest
    {

        public int accountId { get; set; }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for API Constructor
        ///</summary>
        [TestMethod()]
        public void APIConstructorTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            Assert.AreEqual(appId, target.adapter.AppId);
        }

        /// <summary>
        ///A test for API Constructor
        ///</summary>
        [TestMethod()]
        public void APIConstructorTest1()
        {
            string consumerKey = ConfigurationManager.AppSettings["AweberConsumerKey"];
            string consumerSecret = ConfigurationManager.AppSettings["AweberConsumerSecret"];
            API target = new API(consumerKey, consumerSecret);
            Assert.AreEqual(consumerKey, target.adapter.ConsumerKey);
            Assert.AreEqual(consumerSecret, target.adapter.ConsumerSecret);
        }

        /// <summary>
        ///A test for authorize
        ///</summary>
        [TestMethod()]
        public void authorizeTest()
        {
            // Unable to automatically verify due to user input required on opened website.
            // Tested Manually
        }

        /// <summary>
        ///A test for getAccount
        ///</summary>
        [TestMethod()]
        public void getAccountTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            target.process_appId_token(ConfigurationManager.AppSettings["AweberToken"]);

            Account actual;
            actual = target.getAccount();

            Assert.IsNotNull(actual);

            Assert.AreNotEqual(actual.id, null, String.Format("AccountId was: {0}", actual.id));

            accountId = actual.id;

        }

        /// <summary>
        ///A test for get_access_token
        ///</summary>
        [TestMethod()]
        public void get_access_tokenTest()
        {
            // Not valid automated test as requires human interaction on Aweber site
            // Tested manually
        }

        /// <summary>
        ///A test for get_request_token
        ///</summary>
        [TestMethod()]
        public void get_request_tokenTest()
        {
            // Not valid automated test as requires human interaction on Aweber site
            // Tested manually
        }

        /// <summary>
        ///A test for get_request_token
        ///</summary>
        [TestMethod()]
        public void get_request_tokenTest1()
        {
            // Not valid automated test as requires human interaction on Aweber site
            // Tested manually
        }

        /// <summary>
        ///A test for process_appId_token
        ///</summary>
        [TestMethod()]
        public void process_appId_tokenTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            string token = ConfigurationManager.AppSettings["AweberToken"];
            target.process_appId_token(token);

            String[] tokenValues = token.Split('|');

            Assert.AreEqual<String>(appId, target.adapter.AppId);
            Assert.AreEqual<String>(tokenValues[0], target.adapter.ConsumerKey);
            Assert.AreEqual<String>(tokenValues[1], target.adapter.ConsumerSecret);
            Assert.AreEqual<String>(tokenValues[2], target.adapter.OAuthToken);
            Assert.AreEqual<String>(tokenValues[3], target.adapter.OAuthTokenSecret);
            Assert.AreEqual<String>(tokenValues[4], target.adapter.OAuthVerifier);

        }

        /// <summary>
        ///A test for CallbackUrl
        ///</summary>
        [TestMethod()]
        public void CallbackUrlTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            string expected = "http://localhost";
            string actual;
            target.CallbackUrl = expected;
            actual = target.CallbackUrl;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for OAuthToken
        ///</summary>
        [TestMethod()]
        public void OAuthTokenTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            string expected = "TestValue";
            string actual;
            target.OAuthToken = expected;
            actual = target.OAuthToken;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for OAuthTokenSecret
        ///</summary>
        [TestMethod()]
        public void OAuthTokenSecretTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            string expected = "TestValue";
            string actual;
            target.OAuthTokenSecret = expected;
            actual = target.OAuthTokenSecret;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for OAuthVerifier
        ///</summary>
        [TestMethod()]
        public void OAuthVerifierTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API target = new API(appId);
            string expected = "TestValue";
            string actual;
            target.OAuthVerifier = expected;
            actual = target.OAuthVerifier;
            Assert.AreEqual(expected, actual);

        }
    }
}
